<template>
  <div class="qualiy_add">
    <el-dialog
      class="MonitorSufaceADD"
      title="添加地表下沉量测数据"
      :visible.sync="dialogVisible"
      width="40%"
      :before-close="handleClose"
    >
      <el-form ref="form" class="demo-form-inline" :model="form" label-width="120px">
        <!-- 必填 -->
        <el-form-item label="断面">
          <el-select style="width:100%" v-model="form.sId" placeholder="请选择断面">
            <el-option v-for="v in TunnelSection" :label="v.sectionName" :key="v.id" :value="v.id"></el-option>
          </el-select>
        </el-form-item>
        <!-- 必填 -->
        <el-form-item label="测量时间">
          <el-date-picker
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期"
            v-model="form.createTime"
            style="width: 100%;"
          ></el-date-picker>
        </el-form-item>
        <!-- 必填 -->
        <el-form-item label="ZD当日沉降">
          <el-input v-model="form.zdTodaySink"></el-input>
        </el-form-item>
        <el-form-item label="Z1当日沉降">
          <el-input v-model="form.z1TodaySink"></el-input>
        </el-form-item>
        <el-form-item label="Z2当日沉降">
          <el-input v-model="form.z2TodaySink"></el-input>
        </el-form-item>
        <el-form-item label="Z3当日沉降">
          <el-input v-model="form.z3TodaySink"></el-input>
        </el-form-item>
        <el-form-item label="Y1当日沉降">
          <el-input v-model="form.y1TodaySink"></el-input>
        </el-form-item>
        <el-form-item label="Y2当日沉降">
          <el-input v-model="form.y2TodaySink"></el-input>
        </el-form-item>
        <el-form-item label="Y3当日沉降">
          <el-input v-model="form.y3TodaySink"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="create">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
  
  <script>
import api from "../../../api";
import qs from "qs";

export default {
  data() {
    return {
      dialogVisible: false,
      etype: [],
      tunnelList: [],
      TunnelSection: [],
      form: {
        wId: "", //洞幅id
        sId: "", //断面id
        createTime: "",
        z1TodaySink: "",
        z2TodaySink: "",
        z3TodaySink: "",
        y1TodaySink: "",
        y2TodaySink: "",
        y3TodaySink: "",
      },
    };
  },
  mounted() {
    this.$bus.$on("onAddMonitorSurfaceShow", (flag) => {
      if (this.form.wId == "") {
        this.$message({
          type: "fail",
          message: "请选择洞幅",
        });
        this.dialogVisible = false;
      } else {
        this.dialogVisible = true;
      }
    });
    this.$bus.$on("onAddMonitorSurfaceWid", (flag) => {
      this.form.wId = flag;
      this.findByTunnelSection(this.form.wId);
    });
  },
  methods: {
    // 查询断面
    findByTunnelSection(wid) {
      api
        .tunnelSectionfindByWid({ wid })
        .then((res) => {
          if (res.data.code == 2001) {
            this.TunnelSection = res.data.data;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    create() {
      if (this.form.wId == "") {
        this.$message({
          type: "fail",
          message: "请选择洞幅",
        });
        return;
      }
      if (this.form.sId == "") {
        this.$message({
          type: "fail",
          message: "请选择断面",
        });
        return;
      }
      api
        .monitorSurfacesave(qs.stringify(this.form))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: "success",
              message: "添加成功!",
            });
            this.dialogVisible = false;
            this.$bus.$emit("onRefreshmonitorSurface", this.form.wId);
          } else {
            this.$message({
              type: "fail",
              message: res.data.message,
            });
          }
        })
        .catch((err) => {});
    },

    onSubmit() {
      console.log("submit!");
    },
    handleCommand(command) {
      alert(command);
    },
    funsection() {},
  },
};
</script>
  
  <style scoped>
.qualiy_add {
  width: 1000px;
  margin: 10px;
}
.el-dialog {
  width: 40%;
}

.MonitorSufaceADD :deep(.el-input--suffix .el-input__inner) {
  width: 202px;
}
.MonitorSufaceADD :deep(.el-textarea__inner) {
  width: 202px;
}
.MonitorSufaceADD :deep(.el-form--inline .el-form-item__content) {
  width: 202px;
}
</style>